function createPoster(that, path, tools, app, mta) {
    var that = that;
    var count = 0;
    var delay = 0; //生成海报最长延时5秒

    if (parseInt(that.data.Score) > 0) {
        app.aldstat.sendEvent('录音-录音后-点击制成海报');
        mta.Event.stat("record_afterrecord_makeposter", {});
    } else {
        app.aldstat.sendEvent('录音-录音前-点击制成海报');
        mta.Event.stat("record_beforerecord_makeposter", {});
    }

    var width = that.data.windowWidth
    var height = that.data.windowHeight
    var scale = that.data.scale

    console.log('绘制海报');
    var ctx = wx.createCanvasContext('poster');

    wx.showLoading({
        title: '生成海报中...',
        mask: true,
    })

    //绘制白色背景
    ctx.setFillStyle('white');
    ctx.fillRect(0, 0, 310 * scale, 468 * scale);
    ctx.draw();

    //绘制图片
    if (that.data.coverImg) {
        ctx.drawImage(that.data.coverImg, 0, 0, 311 * scale, 175 * scale);
        ctx.draw(true);
        count++;
    } else {
        wx.downloadFile({
            url: that.data.videoImgUrl,
            success: function(res) {
                console.log('下载图片成功', res)
                ctx.drawImage(res.tempFilePath, 0, 0, 311 * scale, 175 * scale);
                ctx.draw(true);
                count++;
                that.setData({
                    coverImg: res.tempFilePath
                });
            },
            fail: function(err) {
                console.log('下载图片失败', err)
                ctx.drawImage('', 0, 0, 311 * scale, 175 * scale);
                ctx.draw(true);
                count++;
            }
        })
    }

    //绘制字幕背景图片
    ctx.drawImage(path.images + 'subtitle_bg.png', 0, 175 * scale, 310 * scale, 323 * scale);
    ctx.draw(true);

    //绘制中英文句子
    var en = that.data.SrtList[that.data.index].English || 'Come and play dubbing with me!';
    var ch = that.data.SrtList[that.data.index].Chinese || '快来跟我一起玩配音';

    //将英语长句分段
    var newEnArr = []; //断句后的英语句组
    var enLength = 33
    var chLength = 17
    if (scale < 1) {
        enLength = 30
        chLength = 15
    }

    for (var k = 0; k < (en.length / enLength); k++) {
        newEnArr.push(en.slice(enLength * k, enLength * (k + 1)));
    }

    //将中文长句分段
    var newChArr = [];
    for (var j = 0; j < (ch.length / chLength); j++) {
        newChArr.push(ch.slice(chLength * j, chLength * (j + 1)));
    }

    ctx.setTextBaseline('middle')
    ctx.setFontSize(15);
    ctx.save()
    ctx.setFillStyle('black');
    newEnArr.forEach(function(v, i) {
        ctx.fillText(v, 30 * scale, (220 + 20 * i) * scale);
    })
    ctx.draw(true);

    ctx.restore();
    ctx.beginPath()
    ctx.setFillStyle('gray')
    newChArr.forEach(function(v, i) {
        ctx.fillText(v, 30 * scale, (230 + k * 20 + 20 * i) * scale);
    })
    ctx.draw(true);

    //绘制白色背景
    ctx.setFillStyle('white');
    ctx.fillRect(0, 320 * scale, 310 * scale, 144 * scale);
    ctx.draw(true);

    //绘制小程序码
    if (that.data.QRcode) {
        ctx.drawImage(that.data.QRcode, 105 * scale, 330 * scale, 90 * scale, 90 * scale);
        ctx.draw(true);
        count++;
    } else {
        tools.getWxCode({
            scene: app.globalData.openId + '&' + that.data.QID,
            page: path.details,
        }, function(res) {
            wx.downloadFile({
                url: 'https://' + res.data.data,
                success: function(res) {
                    console.log('下载二维码成功', res)
                    ctx.drawImage(res.tempFilePath, 105 * scale, 330 * scale, 90 * scale, 90 * scale);
                    ctx.draw(true)
                    count++;
                    that.setData({
                        QRcode: res.tempFilePath
                    })
                },
                fail: function(err) {
                    console.log('下载二维码失败', err);
                    ctx.drawImage(path.images + 'qrcode.jpg', 105 * scale, 330 * scale, 90 * scale, 90 * scale);
                    ctx.draw(true);
                    count++;
                }
            })
        }, function(err) {
            console.log('请求二维码数据失败', err)
            ctx.drawImage(path.images + 'qrcode.jpg', 105 * scale, 330 * scale, 90 * scale, 90 * scale);
            ctx.draw(true);
            count++;
        })
    };

    //长按二维码跳转到小程序
    ctx.setTextBaseline('middle')
    ctx.setFillStyle('#17CCBC')
    ctx.setFontSize(12);
    ctx.fillText("长按识别进入小程序", 98 * scale, 435 * scale);
    ctx.draw(true);

    //显示海报
    that.timer_poster = setInterval(function() {
        console.log(count);
        delay += 500;
        if (count == 2) {
            that.setData({
                hideMask: false
            })
            clearInterval(that.timer_poster);
            wx.hideLoading();
        } else if (delay >= 5000) {
            that.setData({
                hideMask: false
            })
            clearInterval(that.timer_poster);
            wx.hideLoading();
            wx.showToast({
                title: '生成海报超时，请稍后再试',
                duration: 1000
            })
        }
    }, 500)
}

module.exports = createPoster